<?php

namespace humhub\modules\api\controllers;

use humhub\modules\api\models\Scores;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBearerAuth;
use Yii;

/**
 * 积分相关列表 目前仅支持查看积分列表
 */
class ScoresController extends Base4Controller
{


    /**
     * 加入用户权限
     *
     * @inheritdoc
     */
    public function behaviors(){
        $behaviors = parent::behaviors();
        $behaviors['authenticator'] = [
            'class' => CompositeAuth::className(),
            'authMethods' => [
                //QueryParamAuth::className(),
                HttpBearerAuth::className(),
            ],
        ];

        return $behaviors;
    }
    /**
     * 获取用户积分列表 默认每页10条数据
     *
     * GET api/scores/list
     *
     * get.uid 当前用户的id （非guid）
     *
     * @return array （gid 商品id 目前为null，uid 用户id，goods 积分明细，score 积分，time 具体时间）
     */
    public function actionList(){
        $id = (int)Yii::$app->request->get('uid');
        if( ! $id ){
            throw new \yii\web\BadRequestHttpException('用户不存在');
        }
        $pages = new \yii\data\Pagination([
            'defaultPageSize' => 10,
            'validatePage'    => false,
        ]);
        $data=Scores::find()->where(['uid'=>$id])->orderBy('time DESC')->offset($pages->offset)->limit($pages->limit)->all();

        return $data;

    }
}
